package com.ruoyi.zsyh.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.zsyh.domain.ZsyhPlatformSellPartsAttribute;
import com.ruoyi.zsyh.mapper.ZsyhPlatformSellpartsMapper;
import com.ruoyi.zsyh.domain.ZsyhPlatformSellparts;
import com.ruoyi.zsyh.service.IZsyhPlatformSellpartsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 商城零售配件信息Service业务层处理
 * 
 * @author yuexl
 * @date 2025-04-27
 */
@Service
public class ZsyhPlatformSellpartsServiceImpl implements IZsyhPlatformSellpartsService 
{
    @Autowired
    private ZsyhPlatformSellpartsMapper zsyhPlatformSellpartsMapper;

    /**
     * 查询商城零售配件信息
     * 
     * @param id 商城零售配件信息ID
     * @return 商城零售配件信息
     */
    @Override
    public ZsyhPlatformSellparts selectZsyhPlatformSellpartsById(String id)
    {
        return zsyhPlatformSellpartsMapper.selectZsyhPlatformSellpartsById(id);
    }

    /**
     * 查询商城零售配件信息列表
     * 
     * @param zsyhPlatformSellparts 商城零售配件信息
     * @return 商城零售配件信息
     */
    @Override
    public List<ZsyhPlatformSellparts> selectZsyhPlatformSellpartsList(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        return zsyhPlatformSellpartsMapper.selectZsyhPlatformSellpartsList(zsyhPlatformSellparts);
    }

    /**
     * 新增商城零售配件信息
     * 
     * @param zsyhPlatformSellparts 商城零售配件信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertZsyhPlatformSellparts(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        zsyhPlatformSellparts.setCreateTime(DateUtils.getNowDate());
        int rows = zsyhPlatformSellpartsMapper.insertZsyhPlatformSellparts(zsyhPlatformSellparts);
        insertZsyhPlatformSellPartsAttribute(zsyhPlatformSellparts);
        return rows;
    }

    /**
     * 修改商城零售配件信息
     * 
     * @param zsyhPlatformSellparts 商城零售配件信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateZsyhPlatformSellparts(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        zsyhPlatformSellparts.setUpdateTime(DateUtils.getNowDate());
        zsyhPlatformSellpartsMapper.deleteZsyhPlatformSellPartsAttributeByPartsId(zsyhPlatformSellparts.getId());
        insertZsyhPlatformSellPartsAttribute(zsyhPlatformSellparts);
        return zsyhPlatformSellpartsMapper.updateZsyhPlatformSellparts(zsyhPlatformSellparts);
    }

    /**
     * 删除商城零售配件信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteZsyhPlatformSellpartsByIds(String ids)
    {
        zsyhPlatformSellpartsMapper.deleteZsyhPlatformSellPartsAttributeByPartsIds(Convert.toStrArray(ids));
        return zsyhPlatformSellpartsMapper.deleteZsyhPlatformSellpartsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商城零售配件信息信息
     * 
     * @param id 商城零售配件信息ID
     * @return 结果
     */
    @Override
    public int deleteZsyhPlatformSellpartsById(String id)
    {
        zsyhPlatformSellpartsMapper.deleteZsyhPlatformSellPartsAttributeByPartsId(id);
        return zsyhPlatformSellpartsMapper.deleteZsyhPlatformSellpartsById(id);
    }

    /**
     * 新增产品属性信息
     * 
     * @param zsyhPlatformSellparts 商城零售配件信息对象
     */
    public void insertZsyhPlatformSellPartsAttribute(ZsyhPlatformSellparts zsyhPlatformSellparts)
    {
        List<ZsyhPlatformSellPartsAttribute> zsyhPlatformSellPartsAttributeList = zsyhPlatformSellparts.getZsyhPlatformSellPartsAttributeList();
        String id = zsyhPlatformSellparts.getId();
        if (StringUtils.isNotNull(zsyhPlatformSellPartsAttributeList))
        {
            List<ZsyhPlatformSellPartsAttribute> list = new ArrayList<ZsyhPlatformSellPartsAttribute>();
            for (ZsyhPlatformSellPartsAttribute zsyhPlatformSellPartsAttribute : zsyhPlatformSellPartsAttributeList)
            {
                zsyhPlatformSellPartsAttribute.setPartsId(id);
                list.add(zsyhPlatformSellPartsAttribute);
            }
            if (list.size() > 0)
            {
                zsyhPlatformSellpartsMapper.batchZsyhPlatformSellPartsAttribute(list);
            }
        }
    }
}
